// pages/allssemble/allssemble.js
var utils = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentPage: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.groupgoodsList(that.data.currentPage);
    that.memberInfo();
  },
  memberInfo: function() {
    var that = this;
    utils.http("/api/v1/member/index", {}, function(res) {
      that.setData({
        memberInfo: res.datas
      })
    });
  },
  groupgoodsList: function(currentPage) {
    var that = this;
    utils.showLoading();
    utils.http("/api/v1/groupgoods/goods_list", {
      page: currentPage
    }, function(res) {
      utils.hideLoading();
      var allpost = that.data.groupgood;
      if (allpost == undefined) {
        allpost = [];
      }
      for (var i in res.datas) {
        allpost.push(res.datas[i])
      }
      if (res.datas.length < 10) {
        that.setData({
          tishi_title: '已加载全部',
        });
      } else {
        that.setData({
          tishi_title: '加载更多',
        });
      }
      that.setData({
        groupgood: allpost,
        ready: res.datas.length == 0 ? 1 : 2,
      })
    })
  },
  //进入拼团详情
  onAllSsembledetailsTap: function(e) {
    wx.navigateTo({
      url: '../allssembledetails/allssembledetails?id=' + e.currentTarget.dataset.id
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this;
    if (that.data.ready == 2) {
      var page = that.data.currentPage + 1
      that.setData({
        currentPage: page,
      })
      that.groupgoodsList(page);
    }

  },
})